package com.ln.dm1102.demo02;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/2 15:29
 */
public class TestExecutor {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for (int i = 0; i < 5; i++) {
            final int a=i;
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < 20; j++) {
                        System.out.println(Thread.currentThread().getName()+"++++++"+j);
                    }

                }
            });
        }
        //关闭线程池   任务没有做完，就被打断。
        executorService.shutdownNow();

        //判断线程池是否关闭
        boolean shutdown = executorService.isShutdown();
        System.out.println("shutdown = " + shutdown);

        //判断线程池是否终止   里面的任务执行完毕
        boolean terminated = executorService.isTerminated();
        System.out.println("terminated = " + terminated);

    }
}
